//
//  SearchCard.swift
//  shop
//
//  Created by chen on 2025/5/17.
//

import SwiftUI
import Kingfisher

struct SearchResultCard: View {
    
    var item: GoodsItem
    
    var body: some View {
        HStack(spacing: 8) {
            VStack(spacing: 0){
                KFImage.url(URL(string: item.mainPic))
                       .loadDiskFileSynchronously()
                       .cacheMemoryOnly()
                       .fade(duration: 0.35)
                       .resizable()
                       .frame(width: 100, height: 100)
            }
            .frame(width: 100, height: 100)
            .cornerRadius(11)
            
            VStack(alignment: .leading, spacing: 5) {
                Text("\(item.dtitle)")
                    .font(.system(size: 14))
                    .bold()
                    .foregroundStyle(Color.black)
                
                HStack(alignment: .lastTextBaseline, spacing: 0) {
                    Group{
                        Text("券后")
                            .font(.system(size: 13))
                            .padding(.trailing, 2)
                        
                        Text("¥")
                            .font(.system(size: 13))
                        
                        Text("\(item.actualPrice.formatMoney())")
                            .font(.system(size: 20))
                            .lineLimit(1)
                            .minimumScaleFactor(0.5)
                    }
                    .foregroundStyle(Color.red)
                    .bold()
                    
                    Text("原价¥\(item.originalPrice.formatMoney())")
                        .font(.system(size: 13))
                        .foregroundStyle(.gray)
                        .strikethrough()
                        .lineLimit(1)
                        .minimumScaleFactor(0.5)
                        .padding(.leading, 10)
                }
                
                HStack(spacing: 5) {
                    Text("\(item.shopType == 1 ? "天猫" : "淘宝")")
                        .padding(2)
                        .font(.system(size: 11))
                        .bold()
                        .foregroundStyle(.white)
                        .background(Color.red)
                        .cornerRadius(3)
                    
                    Text("\(item.shopName)")
                        .font(.system(size: 13))
                        .foregroundStyle(Color.black)
                        .bold()
                }
                
                Text("销量：\(item.monthSales)")
                    .font(.system(size: 11))
                    .foregroundStyle(.black.opacity(0.55))
            }
            .padding(.top, 5)
            
            Spacer()
        }
        .padding(.horizontal, 10)
        .padding(.vertical, 8)
        .background(.white)
        .cornerRadius(8)
        .padding(.horizontal, 10)
    }
}
